console.log('goodsInfo')
var userId = window.localStorage.getItem('userId')
var supplierId,membershipPrice,specificationModel,price,brandName,goodsPrice,goodsName,goodsNum,goodsTypeId,goodsId,orderstatus;
goodsNum = $('#goodsNum').val()
goodsId = GetQueryString('goodsId');
//获取商品详情信息
$.ajax({
    type:'get',
    url:webUrl+'/goods/findByGoodsId',
    data:{
        goodsId:goodsId
    },
    success:function(data){
        let goodsInfo =data.content;
        supplierId = goodsInfo.supplierId;
        goodsPrice = goodsInfo.concessionalRate; //优惠价
        price = goodsInfo.price;    //原价
        membershipPrice = goodsInfo.membershipPrice; //会员价
        goodsName = goodsInfo.commodityName;  //商品名称
        brandName = goodsInfo.brandName;  // 牌号商标
        // goodsTypeId = goodsInfo.goodsTypeId;
        orderstatus = goodsInfo.orderstatus;
        specificationModel = goodsInfo.specificationModel; // 型号
        if(data.code=='1'){
            $('.specificationModel').html(specificationModel)
            $('.regular').html(price)
            $('.goodsname').html(goodsName)
            $('.category').html(brandName)
            $('.goodsprice').html('$'+goodsPrice)
        }else{
            alert('系统繁忙！请稍后再试！')
        }
    }
})
$('.btn-up').click(function () {
    goodsNum++;
    $('#goodsNum').val(goodsNum)
})
$('.btn-down').click(function () {
    if(goodsNum>0){
        goodsNum--;
    }

    $('#goodsNum').val(goodsNum)
})
//购买商品
$('.btn-add-cart').click(function(){
    if(!userId){
        alert('您还没有登录！')
        return false;
    }
    if(userId == supplierId){
        alert('这是您的宝贝，不需要购买')
        return false
    }
    $.ajax({
        type:'post',
        url:webUrl + '/orders/create',
        data:{
            userId:userId,
            goodsId:goodsId,
            supplieerId:supplierId,
            number:goodsNum,
            price:goodsPrice,
            ordertype:1,
            orderstatus:1,
            beizhu:'备注不能为空'
        },
        success:function(data){
            console.log(data)
            if(data.code == '1'){
                alert('购买成功')
            }
        }
    })
})
